//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __FILEDISK_H__
#define __FILEDISK_H__

#include <driver.h>
#include <filedisk_data.h>

class CFileDisk : public CDeviceDriver
{
public:
    CARAPI Read(
        /* [in] */ Int64 offset,
        /* [in] */ Int32 bytesToRead,
        /* [out] */ MemoryBuf * pBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Write(
        /* [in] */ Int64 offset,
        /* [in] */ const MemoryBuf & buffer,
        /* [out] */ Int32 * pBytesWritten,
        /* [out] */ IEvent * * ppCompletionEvent);

    CARAPI Control(
        /* [in] */ Handle32 controlCode,
        /* [in] */ const MemoryBuf & inBuffer,
        /* [out] */ MemoryBuf * pOutBuffer,
        /* [out] */ IEvent * * ppCompletionEvent);

    void Dispose() {delete this;}

public:
	CFileDisk(WString name);
    virtual ~CFileDisk();
    
    ECode Initialize();

    STATIC ECode S_Create(
        /* [in] */ WString name,
        /* [out] */ IDeviceDriver ** ppDisk);

private:
    ECode OpenWithUnlocked();
    void  CloseWithUnlocked();

private:
    PVoid m_hLock;
    PVoid m_hDisk;
    Int64 m_diskSize;
    WStringBuf_<32> m_diskName;
};

#endif//__FILEDISK_H__
